package com.mc.developmentkit.activitys;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
import android.widget.TextView;
import com.qamaster.android.R;
import com.mc.developmentkit.bean.AboutUsInfo;
import com.mc.developmentkit.config.MCConstant;
import com.mc.developmentkit.https.HttpUtils;
import com.mc.developmentkit.json.Json;
import com.mc.developmentkit.utils.MCUtils;
import com.mc.developmentkit.utils.ToastUtil;
import com.mc.developmentkit.views.TitleManger;


/**
 * Created by John_王明阁 on 2016/5/13.
 */
public class ContactUsActivity extends Activity{

    private ImageView lx_Logo;
    private TextView lx_kefuqq,lx_kfdianhua,lx_guanfangqun,lx_shangwuhezuo,lx_guanfangwangzhan;
    private Dialog loadingDialog;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aboutus);
        TitleManger insetance = TitleManger.getInsetance();
        insetance.setContext(this);
        insetance.setName("联系我们");
        initView();
        initData();
    }

    private void initData() {
        loadingDialog = MCUtils.createLoadingDialog(this);
        loadingDialog.show();
        HttpUtils.GET(mHandler, MCConstant.getAboutUsUrl());
    }

    private void initView() {
        lx_Logo= (ImageView) findViewById(R.id.lx_img);
        lx_kefuqq= (TextView) findViewById(R.id.kefuqq);
        lx_kfdianhua= (TextView) findViewById(R.id.kefudianhua);
        lx_guanfangqun= (TextView) findViewById(R.id.guanfangwanjiaqun);
        lx_shangwuhezuo= (TextView) findViewById(R.id.shangwuhezuo);
        lx_guanfangwangzhan= (TextView) findViewById(R.id.guanfangwangzhan);
    }


    /**
     * 获取联系信息
     */
    Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 1:
                    AboutUsInfo aboutUs = Json.aboutUs(msg.obj.toString());
                    if (aboutUs!=null){
                        MCUtils.fillImage(lx_Logo,aboutUs.appLogo);
                        lx_kefuqq.setText(aboutUs.kfQQ);
                        lx_kfdianhua.setText(aboutUs.kfPhone);
                        lx_guanfangqun.setText(aboutUs.qunNum);
                        lx_shangwuhezuo.setText(aboutUs.swQunNum);
                        lx_guanfangwangzhan.setText(aboutUs.gNet);
                        loadingDialog.dismiss();
                    }else{
                        loadingDialog.dismiss();
                        ToastUtil.showToast("关于我们为空");
                    }
                    break;
                case 2:
                    loadingDialog.dismiss();
                    ToastUtil.showToast("网络异常");
                    break;
            }
        }
    };

}
